import request from '../utils/request';
import type {
  OrderItem,
  CreateOrderParams,
  OrderListResponse,
  OrderDetailResponse
} from './types';

/**
 * 订单相关接口
 */
export default {
  /**
   * 获取订单列表
   * @param params 查询参数
   */
  getOrderList(params?: {
    page?: number;
    pageSize?: number;
    status?: number;
    startTime?: string;
    endTime?: string;
  }) {
    return request.get<OrderListResponse>('/api/order/list', params);
  },

  /**
   * 获取订单详情
   * @param id 订单ID
   */
  getOrderDetail(id: string | number) {
    return request.get<OrderDetailResponse>(`/api/order/${id}`);
  },

  /**
   * 创建订单
   * @param data 订单信息
   */
  createOrder(data: CreateOrderParams) {
    return request.post('/api/order/create', data);
  },

  /**
   * 取消订单
   * @param id 订单ID
   * @param reason 取消原因
   */
  cancelOrder(id: string | number, reason?: string) {
    return request.put(`/api/order/${id}/cancel`, { reason });
  },

  /**
   * 删除订单
   * @param id 订单ID
   */
  deleteOrder(id: string | number) {
    return request.delete(`/api/order/${id}`);
  },

  /**
   * 支付订单
   * @param id 订单ID
   * @param payType 支付方式：1-微信支付，2-支付宝
   */
  payOrder(id: string | number, payType: number) {
    return request.post(`/api/order/${id}/pay`, { payType });
  },

  /**
   * 确认收货
   * @param id 订单ID
   */
  confirmOrder(id: string | number) {
    return request.put(`/api/order/${id}/confirm`);
  },

  /**
   * 评价订单
   * @param id 订单ID
   * @param data 评价信息
   */
  reviewOrder(id: string | number, data: {
    goodsId: string | number;
    rating: number;
    content: string;
    images?: string[];
  }) {
    return request.post(`/api/order/${id}/review`, data);
  },

  /**
   * 申请退款
   * @param id 订单ID
   * @param data 退款信息
   */
  refundOrder(id: string | number, data: {
    reason: string;
    description?: string;
    images?: string[];
  }) {
    return request.post(`/api/order/${id}/refund`, data);
  },

  /**
   * 获取订单物流信息
   * @param id 订单ID
   */
  getOrderLogistics(id: string | number) {
    return request.get(`/api/order/${id}/logistics`);
  },

  /**
   * 获取订单支付状态
   * @param id 订单ID
   */
  getOrderPayStatus(id: string | number) {
    return request.get(`/api/order/${id}/pay-status`);
  },

  /**
   * 获取订单数量统计
   */
  getOrderCount() {
    return request.get('/api/order/count');
  },

  /**
   * 再次购买
   * @param id 订单ID
   */
  rebuyOrder(id: string | number) {
    return request.post(`/api/order/${id}/rebuy`);
  },
};